<cfcomponent output="false">
	<cfset VARIABLES.Options = {username = 'SCF\Userlist', password = 'DefinedMan'} />
	<cfset VARIABLES.PowerShell = CreateObject("webservice", "http://scfcas/PowerShellService/?WSDL", VARIABLES.Options)/>

	<!--- Returns mailbox size for specific username, using powershell --->
	<cffunction name="getMailboxSize" returntype="numeric">
		<cfargument name="username" required="true" />
		<cfset var amount = 0 />
		<cftry>
			<cfset amount = VARIABLES.PowerShell.invoke('
				Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
				Get-MailboxStatistics ' & username & ' | ft -HideTableHead @{ expression={ $_.TotalItemSize.Value.ToBytes() } } | Out-String -Width 10000
			') />
			<cfif isNumeric(amount)>
				<cfreturn Round(amount / 1048576) />
			<cfelse>
				<cfreturn -1 />
			</cfif>

			<cfcatch type="any">
				<cfreturn -1 />
			</cfcatch>
		</cftry>
	</cffunction>
    
    
    <!--- Allow for a powershell string to be excuted --->
    <cffunction name="usePowerShell" returntype="any">
        <cfargument name="PSCommands" type="string" default="get-mailbox XXXTestXXX | out-string -width 10000" />
        <cftry>
            <cfscript>
                result = VARIABLES.PowerShell.Invoke(
                    'add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
                    #arguments.PSCommands#'
                );
                return result;
            </cfscript>
            <cfcatch type="any">
                <cfreturn "[ERROR] - Message: #CFCATCH.Message# Detail: #CFCATCH.Detail#" />
            </cfcatch>
        </cftry>
    </cffunction>
    
</cfcomponent>